﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Tathata.Common.BLL.EntityCollections;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.Managers;
using Tathata.Common.Utils;

namespace Tathata.Web
{
    public partial class SitemapGooglePage : BaseNopPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";
            Response.ContentEncoding = new UTF8Encoding();
            Response.Write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

            Response.Write("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");
            WriteGoogleSitemapForCategories(0);
            Response.Write("</urlset>");
            Response.End();
        }

        protected void WriteGoogleSitemapForCategories(int ParentCategoryID)
        {
            CategoryCollection categories = CategoryManager.GetAllCategories(ParentCategoryID);
            foreach (Category category in categories)
            {
                Response.Write("<url>");
                Response.Write("<loc>" + XmlHelper.XmlEncode(SEOHelper.GetCategoryURL(category.CategoryID)) + "</loc> ");
                Response.Write("<changefreq>" + "monthly" + "</changefreq> ");
                Response.Write("<priority>" + "0.8" + "</priority> ");
                Response.Write("</url>");
                WriteGoogleSitemapForCategories(category.CategoryID);
            }
        }
    }
}
